{template '_header'}
<div class='page-heading'><h2>文章分类  {ifp 'system.site.category.edit'}<small>拖动可以排序</small>{/if}</h2></div>

<form action="" method="post" class='form-validate'>

    <table class="table  table-responsive">
        <thead class="navbar-inner">
        <tr>
            <th style="width:60px;">ID</th>
            <th  style="width:200px;">分类名称</th>
            <th style="width:80px;"></th>
            <th></th>
        </tr>
        </thead>
        <tbody id='tbody-items'>
        {loop $list $row}
        <tr>
            <td>
                {$row['id']}
                <input type="hidden" name="catid[]" value="{$row['id']}" >
            </td>

            <td>
                {ifp 'system.site.category.edit'}
                <input type="text" class="form-control" name="catname[]" value="{$row['name']}" >
                {else}
                {$row['name']}
                {/if}
            </td>
            <td>
                <input type="hidden" class="form-control" name="status[]" value="{$row['status']}">
                <label class='checkbox-inline' onclick="$(this).prev(':hidden').val( $(this).find(':checkbox').get(0).checked?'1':'0' ); ">
                    <input type='checkbox' {if $row['status']==1}checked{/if}  /> 显示
                </label>
            </td>
            <td>
                {ifp 'system.site.category.delete'}
                <a href="{php echo webUrl('system/site/casecategory/delete', array('id' => $row['id']))}" data-toggle='ajaxRemove' class="btn btn-default btn-sm" data-confirm="确认删除此分类?"><i class="fa fa-trash"></i> 删除</a>{/if}
            </td>

        </tr>
        {/loop}
        </tbody>
        <tr>
            <td colspan="5">
                {ifp 'system.site.category.add'}
                <input name="button" type="button" class="btn btn-default" value="添加分类" onclick='addCategory()'>
                {/if}
                {ifp 'system.site.category.edit|system.site.category.add'}
                <input type="submit" class="btn btn-primary" value="保存分类">
                {/if}
            </td>
        </tr>


    </table>
    {$pager}


</form>
<script>

    {ifp 'system.site.category.edit'}
    require(['jquery.ui'],function(){
        $('#tbody-items').sortable();
    })
    {/if}

    function addCategory(){
        var html ='<tr>';
        html+='<td><i class="fa fa-plus"></i></td>';
        html+='<td>';
        html+='<input type="hidden" class="form-control" name="catid[]" value=""><input type="text" class="form-control" name="catname[]" value="">';
        html+='</td>';
        html+='<td>';
        html+='</td>';

        html+='<td></td></tr>';;
        $('#tbody-items').append(html);
    }
</script>

{template '_footer'}